package com.ruoyi.consumer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumer.domain.CWalletCompany;
import com.ruoyi.consumer.service.ICWalletCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司钱包Controller
 * 
 * @author ruoyi
 * @date 2023-10-29
 */
@RestController
@RequestMapping("/consumer/walletCompany")
public class CWalletCompanyController extends BaseController
{
    @Autowired
    private ICWalletCompanyService cWalletCompanyService;

    /**
     * 查询公司钱包列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:walletCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(CWalletCompany cWalletCompany)
    {
        startPage();
        List<CWalletCompany> list = cWalletCompanyService.selectCWalletCompanyList(cWalletCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司钱包列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:walletCompany:export')")
    @Log(title = "公司钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CWalletCompany cWalletCompany)
    {
        List<CWalletCompany> list = cWalletCompanyService.selectCWalletCompanyList(cWalletCompany);
        ExcelUtil<CWalletCompany> util = new ExcelUtil<CWalletCompany>(CWalletCompany.class);
        util.exportExcel(response, list, "公司钱包数据");
    }

    /**
     * 获取公司钱包详细信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,dragon')")
    @GetMapping(value = "/{walletPersonId}")
    public AjaxResult getInfo(@PathVariable("walletPersonId") Integer walletPersonId)
    {
        return success(cWalletCompanyService.selectCWalletCompanyByWalletPersonId(walletPersonId));
    }

    /**
     * 新增公司钱包
     */
    @PreAuthorize("@ss.hasPermi('consumer:walletCompany:add')")
    @Log(title = "公司钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CWalletCompany cWalletCompany)
    {
        return toAjax(cWalletCompanyService.insertCWalletCompany(cWalletCompany));
    }

    /**
     * 修改公司钱包
     */
    @PreAuthorize("@ss.hasPermi('consumer:walletCompany:edit')")
    @Log(title = "公司钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CWalletCompany cWalletCompany)
    {
        return toAjax(cWalletCompanyService.updateCWalletCompany(cWalletCompany));
    }

    /**
     * 删除公司钱包
     */
    @PreAuthorize("@ss.hasPermi('consumer:walletCompany:remove')")
    @Log(title = "公司钱包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{walletPersonIds}")
    public AjaxResult remove(@PathVariable Integer[] walletPersonIds)
    {
        return toAjax(cWalletCompanyService.deleteCWalletCompanyByWalletPersonIds(walletPersonIds));
    }
}
